/*
 * @Author: lcy
 * @Date: 2023-06-30 11:35:06
 * @Last Modified by: lcy
 * @Last Modified time: 2023-06-30 20:53:35
 */

import { API_USER_CONFIG } from '@/config/api/user'
import { request } from '@/utils/request'
import { BasicMangeType } from '@/interface/common'
import { UserMangeType } from '@/interface/model/user'
interface UserSeriviceInterface {
  login: (params: UserMangeType.UserLoginFormState) => Promise<any>
  registry: (params: UserMangeType.UserLoginFormState) => Promise<any>
}
export const useUserSerivice = function (): UserSeriviceInterface {
  class UserService {
    login(params: UserMangeType.UserLoginFormState) {
      const url = API_USER_CONFIG.login()
      return request
        .post(url, params)
        .then(({ data }: BasicMangeType.IAxiosResponse) => {
          return Promise.resolve(data)
        })
        .catch((err: any) => {
          return Promise.reject(err)
        })
    }
    registry(params: UserMangeType.UserLoginFormState) {
      const url = API_USER_CONFIG.registry()
      return request
        .post(url, params)
        .then(({ data }: BasicMangeType.IAxiosResponse) => {
          return Promise.resolve(data)
        })
        .catch((err: any) => {
          return Promise.reject(err)
        })
    }
  }
  return new UserService()
}
